package com.huans.util;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBUtil {

	private static Properties props = null;
	private static Connection conn = null;

	static {
		try {
			props = new Properties();
			props.load(DBUtil.class.getClassLoader().getResourceAsStream(
					"jdbc.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection() {
		String driverClassName = props.getProperty("jdbc.driverClassName");
		String url = props.getProperty("jdbc.url");
		String username = props.getProperty("jdbc.username");
		String password = props.getProperty("jdbc.password");
		try {
			Class.forName(driverClassName);
			conn = DriverManager.getConnection(url, username, password);
			System.out.println("create connection conn:" + conn.getCatalog());
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
}
